#include "task_keyScan.h"
#include "tasksInit.h"

#include <stdio.h>

#include "los_task.h"
#include "los_queue.h"
#include "los_event.h"

#include "bsp_led.h"
#include "bsp_key.h"
#include "bsp_beep.h"
#include "bsp_oled.h"
#include "bsp_e53.h"

#include "SystemMonitor.h"

unsigned int task_keyScan_id;
TSK_INIT_PARAM_S task_keyScan_handler = {
    (TSK_ENTRY_FUNC)task_keyScan,
    21,
    0,
    1280,
    "task_keyScan",
    0
};

void task_keyScan(void)
{
    e53_data_t e53_data;
    KEY_TYPE key = 0;

    LOS_EventRead(&bspInit_ECB, BSPINIT_EVENT_INITOK, LOS_WAITMODE_AND, LOS_WAIT_FOREVER);

    while(1)
    {
        key = key_scan(0);
        
        switch(key)
        {
        case KEY1_PRES:
            LOS_QueueWriteCopy(pageManage_qId, (void *)&key, sizeof(key), 1);

            break;

        case KEY2_PRES:
            LOS_QueueWriteCopy(pageManage_qId, (void *)&key, sizeof(key), 1);

            break;

        case KEY3_PRES:
            e53_ia_read_data(&e53_data);
            printf("[e53 data] hum:%.2f tem:%.2f lum:%.2f \n", e53_data.humidity, e53_data.temperature, e53_data.luminance);

            get_los_status();
            get_one_second_tick();
            
            break;

        case KEY4_PRES:
            LOS_QueueWriteCopy(pageManage_qId, (void *)&key, sizeof(key), 1);

            break;

        default:
            break;
        }

        LOS_Msleep(20);

    }
}
